#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: update_01_tag_pinType_20210506.py
# @time: 2021/5/6 14:33
# @desc:
import pymongo

from .utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from .views.configs import HISTORY_CLAMP_COLLECTION, MONGO_DATABASE_NAME

all_history_clamps = retrieve_all_mongo_values({}, database_name=MONGO_DATABASE_NAME,collection_name=HISTORY_CLAMP_COLLECTION)

for i in all_history_clamps:
    if "pinType" in i["tag"].keys():
        if i["tag"]["pinType"] == "暂无" or i["tag"]["pinType"] == "":
            i["tag"]["pinType"] = []
        elif type(i["tag"]["pinType"]) is str:
            i["tag"]["pinType"] = [i["tag"]["pinType"]]
    else:
        i["tag"]["pinType"] = []

    updateInfo = {"$set": i}
    update_mongo_value(filter_condition={'number': i["number"]}, new_value=updateInfo, database_name=MONGO_DATABASE_NAME, collection_name=HISTORY_CLAMP_COLLECTION)